<?php

require_once('BaseModel.php');

class Sites extends BaseModel {
	protected $_name = "sites";
	
	function getByDomain( $domain = null){
		if( $domain ){
			
			$query = $this->select()
						  ->where( "urls LIKE ? ", '%"'.$domain.'"%')
						  ->limit( 1 );
			
			$data = $this->_db->query( $query );
			$result = $data->fetchAll();
			if( $result ){
				return ( reset($result) );
			}
		}
		return null;
	}
	
	function getById( $id, $pKey = "id" , $sites_id = NULL ){
		//OBJECT
		$select = $this->getSelectObject();
		$select->where( 'status != ?', '2' )
			   ->where( $pKey.' = ?', $id );

		$this->setSelectObject( $select );
		$select = $this->getSelectObject(); 
		
		$data = $this->fetchAll( $select );

		$objData = NULL;
		if( $data->count() )
			$objData = $data->current()->toArray();

		return $objData;
	}
}